import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-10-31
 * Time: 21:45
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if(n == 0) {
            System.out.println(0);
        }
        int[] prices = new int[n];
        for(int i = 0; i < n; i++) {
            prices[i] = in.nextInt();
        }
        //int min = prices[0];
        //int max = prices[n-1];
        int i = 0;
        int j = n - 1;
        int minIndex = 0;//记录最小买入价格的下标
        int maxIndex = n-1;//记录最大卖出价格的下标
        while(i < n && j >= 0) {
            if(i <= maxIndex && prices[i] < prices[minIndex]) {
                minIndex = i;
            }
            if(j >= minIndex && prices[j] > prices[maxIndex]) {
                maxIndex = j;
            }
            i++;
            j--;
        }
        System.out.println(prices[maxIndex]-prices[minIndex]);
    }
}
